<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link rel="stylesheet"
	href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="resources/css/doctor/doctor.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="resources/js/doctor/doctor.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<div class="doctor_div">
	<div id="tabs">
		<ul>
			<li><a id="tabs-1m" href="#tabs-1">처방</a></li>
			<li><a id="tabs-2m" href="#tabs-2">처방내역</a></li>
			<li><a id="tabs-3m" href="#tabs-3">파일</a></li>
			<li><a id="tabs-4m" href="#tabs-4">진단서</a></li>
		</ul>
		<div id="tabs-1">
			<fieldset style="width: 200px;">
				<legend>의사정보</legend>
				<table>
					<tr>
						<td>의사번호
						<td>의사이름</td>
					</tr>
					<tr>
						<td><input type="text" value="${doctor_id2}" id="doctor_id"
							name="doctor_id" readonly="readonly"></td>
						<td><input type="text" value="${name2}" id="name" name="name"
							readonly="readonly"></td>
					</tr>
				</table>
			</fieldset>
			<div id="patientinfo">
				<fieldset style="width: 673px;">
					<legend>환자정보</legend>
					<table>
						<tr>
							<td>환자번호</td>
							<td>환자이름</td>
							<td>생년월일</td>
							<td>성별</td>
							<td>접수번호</td>
							<td>진단서환자여부</td>
						</tr>
						<tr>
							<td><input type="text" id="patient_id" readonly
								name="patient_id"></td>
							<td><input type="text" id="name" name="name" readonly></td>
							<td><input type="text" id="jumin" name="jumin1" readonly></td>
							<td><input type="text" id="gender" name="gender" readonly></td>
							<td><input type='text' id='jupsoo_id' name='jupsoo_id'
								readonly></td>
							<td id="jindanseo_check"></td>
						</tr>
					</table>
				</fieldset>
			</div>
			<div id="is_ward_div">
				<fieldset>
					<legend>입원여부</legend>
					<table>
						<tr>
							<td>입원여부</td>
						</tr>
						<tr>
							<td><select id="is_ward" name="is_ward">
									<!-- <option selected >-입원여부선택-</option> -->
									<option value="Y">입원</option>
									<option value="N" selected>입원 안함</option>
							</select></td>
						</tr>
					</table>
				</fieldset>
			</div>
			<div class='habitat_detail_id'>
				<fieldset>
					<legend>서식지</legend>
					<table>
						<tr>
							<td>서식지 선택</td>
							<td>대분류</td>
							<td>소분류</td>
						</tr>
						<tr>
							<td><button type="button" id="seosikbtn">선택</button> <input
								type="hidden" class="num" name="habitat_detail_id"></td>
							<td><input type="text" class="dae" name="type" readonly></td>
							<td><input type="text" class="so" name="content" readonly></td>
						</tr>
					</table>
				</fieldset>
			</div>
			<fieldset style="width: 474px;">
				<legend>검사</legend>
				<table>
					<tr>
						<td>검사장소</td>
						<td>검사유형</td>
						<td>검사실이동</td>
					</tr>
					<tr>
						<td><select id="geomsa_code_id">
								<option value="Gcode03" selected>--검사장소--</option>
								<option value="Gcode01">방사선실</option>
								<option value="Gcode02">체혈실</option>
						</select></td>
						<td><select id="fee_id">
								<option value="99" selected>--검사유형--</option>
								<option value="68">단순촬영</option>
								<option value="56">기능검사</option>
								<option value="60">조직병리검사</option>
								<option value="74">CT</option>
								<option value="78">치료방사선</option>
						</select></td>
						<td><button type="button" class="TestmoveBtn">이동</button></td>
					</tr>
				</table>
			</fieldset>
			<fieldset>
				<legend>상병선택</legend>
				<table>
					<tr>
						<td>상병선택</td>
						<td>상병코드</td>
						<td>상병이름</td>
						<td>상병추가</td>
					</tr>
					<tr>
						<td>
							<button type="button" id="diseasebtn">선택</button>
						</td>
						<td><input type="text" class="diseasecode" readonly></td>
						<td><input type="text" class="diseasename" readonly></td>
						<td><button type="button" class="diseaseaddBtn">추가</button></td>
					</tr>
				</table>
			</fieldset>
			<fieldset style="width: 557px;">
				<legend>약선택</legend>
				<table>
					<tr>
						<td>약선택</td>
						<td>CODE</td>
						<td>NAME</td>
						<td>AMOUNT</td>
						<td>UNIT</td>
						<td>약추가</td>
					</tr>
					<tr>
						<td><button type="button" id="medicinebtn">선택</button></td>
						<td><input type="text" class="medicode" readonly></td>
						<td><input type="text" class="mediname" readonly></td>
						<td><input type="text" class="mediamount"></td>
						<td><input type="text" class="mediunit" readonly></td>
						<td>
							<button type="button" class="medicineAddBtn">추가</button>
						</td>
					</tr>
				</table>
			</fieldset>
			<fieldset>
				<legend>복용법</legend>
				<table>
					<tr>
						<td>복용법 선택</td>
					</tr>
					<tr>
						<td><select id="Dose_id" name='Dose_id'><option
									selected>-복용법 선택-</option>
								<c:forEach items="${doselist}" var="doselist">
									<option value='${doselist.dose_id }'>${doselist.name }</option>
								</c:forEach>
						</select></td>
					</tr>
				</table>
			</fieldset>
			<fieldset style="width: 446px;">
				<legend>소견</legend>
				<textarea rows="3" cols="51" id="opinion" name="opinion" style="resize: none;"></textarea>
			</fieldset>

			<div class="jindan_table_div">
				<fieldset>
					<legend>진단 받은 병목록</legend>
					<div>
						<table class="jindan_table">
							<tr class="jindan_tr1">
								<th class="width100px">상병코드</th>
								<th>상병이름</th>
							</tr>
						</table>
					</div>
				</fieldset>
			</div>
			<div class="cheobang_list_div">
				<fieldset>
					<legend>처방 약 목록</legend>
					<div>
						<table class="chebang_table">
							<tr class="zzz">
								<th>약 코드</th>
								<th>약 이름</th>
								<th>개수</th>
								<th>단위</th>
							</tr>
						</table>
					</div>
				</fieldset>
			</div>
		</div>
		<div id="tabs-2">
			<div class="jindan_table_div">
				<fieldset>
					<legend>진단 받은 병 내역</legend>
					<div>
						<table class="jindan_table2">
							<tr class="jindan_tr1">
								<th class="width100px">상병코드</th>
								<th>상병이름</th>
							</tr>
						</table>
					</div>
				</fieldset>
			</div>
			<div class="cheobang_list_div">
				<fieldset>
					<legend>처방 받은 약 내역</legend>
					<div>
						<table class="chebang_table2">
							<tr class="zzz">
								<th class="width100px">약 코드</th>
								<th>약 이름</th>
								<th class="width100px">개수</th>
								<th class="width100px">단위</th>
							</tr>
						</table>
					</div>
				</fieldset>
			</div>
		</div>
		<script type="text/javascript">
			var jupsoo_id = "";
			var patient_id = "";
			var canvas = "";
			var ctx2 = "";
			$(document).on("click","#tabs-3m",	function() {

								jupsoo_id = $("input[name='jupsoo_id']").val();
								patient_id = $("input[id='patient_id']").val();
								$.ajax({
											url : "files.do",
											data : "patient_id=" + patient_id,
											dataType : "json",
											success : function(data) {
												$('.img_list').empty();
												var html = "";
												html += "<tr class='imglist_Tr'><th>환자 번호</th><th>환자 명</th><th>접수 날짜</th></tr>";
												for (var i = 0; i < data.filesview.length; i++) {
													html += "<tr class='imglist_Tr2'>";
													html += "<td>" + patient_id
															+ "</td>";
													html += "<td>"
															+ data.filesview[i].name
															+ "</td>";
													html += "<td>"
															+ data.filesview[i].jupsoo_date;
													html += "<input type='hidden' value='"+data.filesview[i].addfile+"' class='file' name='file'>";
													html += "<input type='hidden' value='"+data.filesview[i].jupsoo_id+"' class='jupid' name='jupid'></td></tr>";
												}
												$('.img_list').append(html);
											}
										});

								$(document).on("click",".imglist_Tr2",function() {
													$('#canvasbox').empty();
													ctx2 = "";
													var idx = $('.imglist_Tr2').index(this);
													var fname = $('.file').eq(idx).val();
													var jupid = $('.jupid').eq(idx).val();
													canvas = document.getElementById('canvasbox');
													var ctx = canvas.getContext('2d');
													var imageObject = new Image();
													imageObject.src = "resources/images/upload/" + fname;
													imageObject.onload = function() {
														ctx.drawImage(imageObject, 0, 0, 400, 450);
													}
												});
							});

			if (window.addEventListener) {
				window.addEventListener('load', InitEvent, false);
			}

			var canvas, context, tool, position;
			//Canvas 그릴 상태 설정
			function InitEvent() {
				canvas = document.getElementById('canvasbox');
				context = canvas.getContext('2d');
				context.strokeStyle = 'red';
				context.lineJoin = 'round';
				context.lineWidth = '1.5';

				// Pencil tool 객체를 생성 한다.
				tool = new tool_pencil();
				canvas.addEventListener('mousedown', ev_canvas, false); //마우스 다운 이벤트
				canvas.addEventListener('mousemove', ev_canvas, false); //마우스 무브 이벤트
				canvas.addEventListener('mouseup', ev_canvas, false); //마우스 업 이벤트
			}

			//그리기 
			function tool_pencil() {
				var tool = this;
				this.started = false;
				// 마우스를 누르는 순간 그리기 작업을 시작 한다. 
				this.mousedown = function(ev) {
					context.beginPath();
					context.moveTo(ev._x, ev._y);
					tool.started = true;
				};
				// 마우스가 이동하는 동안 계속 호출하여 Canvas에 Line을 그려 나간다
				this.mousemove = function(ev) {
					if (tool.started) {
						context.lineTo(ev._x, ev._y);
						context.stroke();
					}
				};
				// 마우스 떼면 그리기 작업을 중단한다
				this.mouseup = function(ev) {
					if (tool.started) {
						tool.mousemove(ev);
						tool.started = false;
					}
				};
			}

			// Canvas요소 내의 좌표를 결정 한다.
			function ev_canvas(ev) {
				position = $(this).offset();
				if (ev.pageX || ev.pageY == 0) { // Firefox 브라우저
					ev._x = event.pageX - position.left
					ev._y = event.pageY - position.top;
				}
				// tool의 이벤트 핸들러를 호출한다.
				var func = tool[ev.type];
				if (func) {
					func(ev);
				}
			}
		</script>
		<div id="tabs-3" class="tab3">
			<div class="xray_img" style="display: inline-block; margin-top:10px;">
				<canvas id="canvasbox" width="400" height="450"></canvas>
			</div>
			<fieldset class="tab3fieldset">
				<legend>검사 받은 자료 목록</legend>
				<div class="img_list_content">
					<table class="img_list">
					</table>
				</div>
			</fieldset>
		</div>
		<div id="tabs-4">
			<div>
				<select id="ca_name" name="ca_name" onchange="select(this.value);">
					<option class="selected_jindan" value="default" selected>
						-- 진단서 유형 --</option>
					<option value="CTF01">상해 진단서</option>
					<option value="CTF02">사망 진단서</option>
				</select>
			</div>
			<div class="sanghae" id="sanghae" style="display: none;">
				<h1>상 해 진 단 서</h1>
				<table class="jindan_sanghae">
					<tr>
						<th class="th_sanghae">진단서 등록번호</th>
						<td class="td_sanghae"><input type="text"
							class="jindanseo_jupsoo_id" name="jindanseo_jupsoo_id" readonly></td>
					</tr>
					<tr>
						<th class="th_sanghae">환자 이름(대상자)</th>
						<td class="td_sanghae"><input type="text" class="name"
							name="name" readonly></td>
					</tr>
					<tr>
						<th class="th_sanghae">주민등록 번호</th>
						<td class="td_sanghae"><input type="text" class="jumin1"
							name="jumin1" readonly> - <input type="text"
							class="jumin2" name="jumin2" readonly></td>
					</tr>
					<tr>
						<th class="th_sanghae">질 병 명</th>
						<td class="td_sanghae"><input type="text"
							placeholder="해당 환자의 병명 입력"></td>
					</tr>
					<tr>
						<th class="th_sanghae">상해(발병)일자</th>
						<td class="td_sanghae"><input type="text" class="injury_date"
							placeholder="일자 입력"></td>
					</tr>
					<tr>
						<th class="th_sanghae">의사 소견</th>
						<td class="td_sanghae"><textarea rows="6" cols="50"
								placeholder="의사 소견 입력"></textarea></td>
					</tr>
					<tr>
						<th class="th_sanghae">진단서 발행일자</th>
						<td class="td_sanghae"><input type="text" name="jupsoo_date"
							readonly class="jupsoo_date" placeholder="2014-08-11"></td>
					</tr>
					<tr>
						<th class="th_sanghae">담당 의사</th>
						<td class="td_sanghae"><input type="text" readonly
							value="${name2}"></td>
					</tr>
				</table>
			</div>
			<div class="sanghae" id="samang" style="display: none;">
				<h1>사 망 진 단 서</h1>
				<table class="jindan_sanghae">
					<tr>
						<th class="th_sanghae">진단서 등록번호</th>
						<td class="td_sanghae"><input type="text"
							class="jindanseo_jupsoo_id2" readonly name="jindanseo_jupsoo_id2"></td>
					</tr>
					<tr>
						<th class="th_sanghae">환자 이름(대상자)</th>
						<td class="td_sanghae"><input type="text" class="name2"
							readonly name="name2"></td>
					</tr>
					<tr>
						<th class="th_sanghae">주민등록 번호</th>
						<td class="td_sanghae"><input type="text" class="jumin3"
							readonly name="jumin3"><input type="text" class="jumin4"
							readonly name="jumin4"></td>
					</tr>
					<tr>
						<th class="th_sanghae">사망 일자</th>
						<td class="td_sanghae"><input type="text" class="death_date"
							placeholder="사망일자 입력"></td>
					</tr>
					<tr>
						<th class="th_sanghae">사망 장소</th>
						<td class="td_sanghae"><input type="text"
							class="death_location" placeholder="사망 장소 입력"></td>
					</tr>
					<tr>
						<th class="th_sanghae">상해(발병)일자</th>
						<td class="td_sanghae"><input type="text"
							placeholder="상해일자 입력"></td>
					</tr>
					<tr>
						<th class="th_sanghae">의사 소견</th>
						<td class="td_sanghae"><textarea rows="6" cols="50"
								placeholder="의사 소견 입력"></textarea></td>
					</tr>
					<tr>
						<th class="th_sanghae">진단서 발행일자</th>
						<td class="td_sanghae"><input type="text" readonly
							name="jupsoo_date2" class="jupsoo_date2" placeholder="발행일자 입력"></td>
					</tr>
					<tr>
						<th class="th_sanghae">담당 의사</th>
						<td class="td_sanghae"><input type="text" readonly
							value="${name2}"></td>
					</tr>
				</table>
			</div>
			<div class="btn_complete">
				<button type="button">초기화</button>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<button type="button" class="jindan_btn">완 료</button>
			</div>
		</div>
	</div>
</div>
<div class="waiting_div">
	<div id="ddd" style="display: none; margin-top: 10px;">
		${list2.patient_id}${list2.jupsoo_time }${list2.name}</div>
	<div class="list" style="text-align: center;">

		<div id="infoDiv"></div>
		<div id="Info" class="Info"></div>
		<input type="hidden" name="cheobang_temp_id" class="cheobang_temp_id">
		<button type="button" class="button1" id="button1">진료</button>
		<button type="button" class="delbutton">삭제</button>

		<!-- 환자 대기리스트 start -->
		<div class="waitinglist_content">
		<h4>현재 대기인원   :   &nbsp;<font color="#6A5ACD"><b>${count}</b></font></h4>
			<table class="watinglist_table">
				<tr>
					<th>환자명</th>
					<th>접수시간</th>
				</tr>
				<c:forEach items="${list}" var="list2">
					<tr class="selectname">
						<td><input class="textval" id="jupsooID" name="jupsoo_id"
							type="hidden" value="${list2.jupsoo_id}" readonly><input
							class="textval" type="hidden" id="patientName"
							value="${list2.name }" readonly>${list2.name }</td>
						<td><input class="textval" type="hidden" id="jupsooTime"
							value="${list2.jupsoo_time}" readonly>${list2.jupsoo_time}
							<input id="infolist" type="hidden"
							value="${list2.patient_id} | ${list2.name} | ${list2.jupsoo_time}">
							<input id="patientid" name="patientid" style="display: none;"
							type="text" value="${list2.patient_id}"> <input
							type="hidden" name="content" class="content"
							value="${list2.content }"> <input type="hidden"
							name="type" class="type" value="${list2.type }"></td>
					</tr>
				</c:forEach>
			</table>
		</div>
		<button type="button" class="cheobangBtn">처 방</button>
		<!-- 환자 대기리스트 end -->

		<div class="is_jindanseo_div"
			style="display: none; text-align: center;">
			<button type="button" class="JindanseoBtn">진단서</button>
		</div>
	</div>

	<div class="search_body" id="search_body" style="display: block;">
		<div class="search_content" id="seosik_div" style="display: none;">
			<div class="search">
				<input type="text" class="inputSize" id="inputtag">
				<button type="button" class="button1" id="seosik_searchbtn">검색</button>
			</div>
			<table class="ptr">
			</table>
		</div>

		<div class="search_content" id="disease_div" style="display: none;">
			<div class="search">
				<input type="text" id="inputtag2">
				<button type="button" class="button1" id="diseasesearchbtn">검색</button>
			</div>
			<table class="ptr">
			</table>
		</div>

		<div class="search_content" id="medicine_div" style="display: none;">
			<div class="search">
				<input type="text" id="inputtag3">
				<button type="button" class="button1" id="medi_search">검색</button>
			</div>
			<table class="ptr">
			</table>
		</div>

	</div>
</div>
<form action="cheobang_insert.medic" class="cheobanginsert"></form>


<%-- <div class="body1">

		<div class="total">
			<div class="content">
				<div id="tabs">
					<ul>
						<li><a id="tabs-1m" href="#tabs-1">처 방</a></li>
						<li><a id="tabs-2m" href="#tabs-2">처방 내역</a></li>
						<li><a id="tabs-3m" href="#tabs-3">파 일</a></li>
						<li><a id="tabs-4m" href="#tabs-4">진 단 서</a></li>
					</ul>


					<!-- tabs1 -->

					<div id="tabs-1">
						
						
						<div class="tabs1_content">
						
						<input type="button" value="의사정보">
							<input type="text" value="${doctor_id2}" id="doctor_id"
								name="doctor_id" readonly="readonly">
							<!-- 의사 코드 -->
							<input type="text" value="${name2}" id="name" name="name"
								readonly="readonly">
							<!-- 의사 이름 -->



							<!-- 환자 정보 -->
								<div id="patientinfo">
								<input type="button" value="환자정보">
									<input type="text" id="patient_id" readonly name="patient_id" placeholder="환자번호" >
									<!-- 환자 코드  -->
									<input type="text" id="name" name="name" placeholder="환자명" readonly> 
									<input type="text" id="jumin" name="jumin1" placeholder="주민등록번호" readonly> 
									<input type="text" id="gender" name="gender" placeholder="성별" readonly> 
									 <input type='button' value='접수번호'><input type='text' id='jupsoo_id' name='jupsoo_id' readonly>									
									 
									 <br><input type='button' value='입원여부'>
									 <select id="is_ward">
									 <option selected>-입원여부선택-</option>
										<option value="Y">입원</option>
										<option value="N" selected>입원 안함</option>
									</select>
									<div id="ward">
									</div>
									<div class="habitat_detail_id">
									<input type="button" id="seosikbtn" value="서식지 선택"> <br>
									<input type="button" value="대분류">
									<input type="text" class="dae" name="type" readonly> 
									<input type="button" value="소분류">
									<input type="text" class="so" name="content" readonly>
									<input type="hidden" class="num" name="habitat_detail_id">
								</div>
								</div>
								
								<!-- 서식지 -->
								
								<div class="geomsa_code_id">
								<input type="button" value='검사'>
									<select id="geomsa_code_id">
										<option value="Gcode03" selected>--검사장소--</option>
										<option value="Gcode01">방사선실</option>
										<option value="Gcode02">체혈실</option>
									</select>
									<select id="fee_id">
										<option value="99" selected>--검사유형--</option>
										<option value="68">단순촬영</option>
										<option value="56">기능검사</option>
										<option value="60">조직병리검사</option>
										<option value="74">CT</option>
										<option value="78">치료방사선</option>
									</select>
									&nbsp;&nbsp;
									<button type="button" class="TestmoveBtn" >검사실 이동</button>
								</div>
								
								<!-- 상병 선택 -->
								<div class='inputall'>
									<input type="button" id="diseasebtn" value="상병 선택"> 
									<input type="text" class="diseasecode"  placeholder="상병코드" readonly> 
										<input type="text" class="diseasename" placeholder="상병이름" readonly>
										<button type="button" class="diseaseaddBtn">병 추가</button>  
										
										<!-- 약 선택 -->
										<br><input type="button" id="medicinebtn" value="약 선택">
										<input type='button' value='code'>
									<input type="text" placeholder="약 코드" class="medicode" readonly> 
									<input type='button' value='name'>
									<input
										type="text" placeholder="약 이름" class="mediname" readonly>
										<br>
										<input type='button' value='amount' class='amount'>  
										<input type="text" class="mediamount"placeholder="개수 입력"> 
										<input type='button' value='unit'>
										<input type="text" class="mediunit" placeholder="단 위" readonly><button type="button" class="medicineAddBtn">약 추가</button>
										<br><input type='button' value='복용법'>
										<select id="Dose_id" name='Dose_id'>
											<option selected>-복용법 선택-</option>
											<c:forEach items="${doselist}" var="doselist">
											<option value='${doselist.dose_id }'>${doselist.name }</option> 
											</c:forEach>
										</select>
								</div> 
								<div>
									<textarea rows="3" cols="60" placeholder="의사 소견 입력 란" name="opinion"></textarea>
									
									<!--
 									<div class="cheobang_btn">
										<table class="c_btn">
			
										</table>
									</div>
									-->
									
									<div class="a">
										<p>
											<strong>진단 받은 병 목록</strong>
										</p>
									</div>
									<div class="jindan_list">
										<table class="jindan_table">
											<tr class="jindan_tr1">
												<th>상병코드</th>
												<th>상병이름</th>
											</tr>
											
										</table>
									</div>

									<div class="a">
										<p>
											<strong>처방 약 목록</strong>
										</p>
									</div>
									<div class="cheobang_list" style="float:left;margin-right: 20px;">
										<table class="chebang_table">
											<tr class="zzz">
											
												<th>약 코드</th>
												<th>약 이름</th>
												<th>개수</th>
												<th>단위</th>
											</tr>
											
											 <tr class="chebang_Tr">
											</tr> 
										</table>
									
									</div>


								</div>
						</div>

					</div>

			<form action="cheobang_insert.medic" class="cheobanginsert">
				
			</form>




					<!-- **************************  tabs2  *************** -->
		<script type="text/javascript">
		
		
		$(document).on("click", ".ui-tabs-anchor", function(){
			
			var patient_id = $("input[id='patient_id']").val();
			
			$.ajax({
				url: "cheobang_history.do",
			
				data: "patient_id="+patient_id,
				success : function(data){
					
					var html = "<tr class='jindanTr'><th>상병명</th><th>병 번호</th></tr>";
					for(var i = 0; i < data.list.length; i++){
						html += "<tr>";
						html += "<td>"+data.list[i].disease_NAME+"</td>";
						html += "<td>"+data.list[i].disease_ID+"</td></tr>";
						}
					$(".jindanTr").html(html);
					
							$.ajax({
								url: "medi_cheobang.do",
								data: "patient_id="+patient_id,
								
								success : function(tata){
									var htm = "<tr class='cheobangTr'><th>약 이름</th><th>약 코드</th><th>개수</th><th>단위</th></tr>";
									for(var i = 0; i < tata.list2.length; i++){
										htm += "<tr>";
										htm += "<td>"+tata.list2[i].medicine_id+"</td>";
										htm += "<td>"+tata.list2[i].medi_name+"</td>";
										htm += "<td>"+tata.list2[i].unit+"</td>";
										htm += "<td>"+tata.list2[i].quantity+"</td></tr>";
										}
									$(".cheobang_Tr").html(htm);
							}
					});
				}
			});
			
			
			
			
		});
		
		</script>
					<div id="tabs-2">

						<p>
							<strong>진단 받은 병 내역</strong>
						</p>
						<div class="jindan_list">

							<table class="jindan_table">
								<tr class="jindanTr">
								<th>상병명</th><th>병 번호</th></tr>
								
								
							</table>
						</div>


						<p>
							<strong>처방 받은 약 내역</strong>
						</p>
						<div class="cheobang_list">
							<table class="chebang_table">
								<tr class="cheobang_Tr">
									<th>약 이름</th>
									<th>약 코드</th>
									<th>개수</th>
									<th>단위</th>
								</tr>
								
							</table>

						</div>
					</div>


<script type="text/javascript">
	var jupsoo_id = "";
	var patient_id = "";
	var canvas = "";
	var ctx2 = "";
	
		$(document).on("click", "#tabs-3m", function(){
			//alert("떴다");
			jupsoo_id = $("input[name='jupsoo_id']").val();
			patient_id = $("input[id='patient_id']").val();
			//alert(patient_id);
			//alert(jupsoo_id);
			$.ajax({
				url : "files.do",
				data : "patient_id="+patient_id,
				dataType :"json",
				success : function(data){
					//alert("성공");
					$('.img_list').empty();
					var html = "";
					html += "<tr class='imglist_Tr'><th>환자 번호</th><th>환자 명</th><th>접수 날짜</th></tr>";
					for(var i = 0; i<data.filesview.length;i++){
						html += "<tr class='imglist_Tr2'>";
						html += "<td>"+patient_id+"</td>";
						html += "<td>"+data.filesview[i].name+"</td>";
						html +=  "<td>"+data.filesview[i].jupsoo_date;
						html += "<input type='hidden' value='"+data.filesview[i].addfile+"' class='file' name='file'>";
						html += "<input type='hidden' value='"+data.filesview[i].jupsoo_id+"' class='jupid' name='jupid'></td></tr>";
					}
					$('.img_list').append(html);
				}
			});
			
			$(document).on("click", ".imglist_Tr2", function(){
					$('#canvasbox').empty();
					//canvas.width = canvas.width;
					ctx2 = "";
					var idx = $('.imglist_Tr2').index(this);
					var fname = $('.file').eq(idx).val();
					var jupid = $('.jupid').eq(idx).val();
					canvas = document.getElementById('canvasbox');
					var ctx = canvas.getContext('2d');
					var imageObject = new Image();

					imageObject.src = "resources/images/upload/"+fname;
					imageObject.onload = function(){
						ctx.drawImage(imageObject, 0, 0, 350, 400);
					}
			});
		});
		
		if(window.addEventListener){
		    window.addEventListener('load', InitEvent, false); 
		}
		
		var canvas, context, tool, position;     
		//Canvas 그릴 상태 설정
		function InitEvent () {                                       
		    canvas = document.getElementById('canvasbox');
		    context = canvas.getContext('2d');
		    context.strokeStyle = 'red';
		    context.lineJoin = 'round';
		    context.lineWidth = '1.5';
		   
		    // Pencil tool 객체를 생성 한다.
		    tool = new tool_pencil();
		    canvas.addEventListener('mousedown', ev_canvas, false); //마우스 다운 이벤트
		    canvas.addEventListener('mousemove', ev_canvas, false); //마우스 무브 이벤트
		    canvas.addEventListener('mouseup',   ev_canvas, false); //마우스 업 이벤트
		}
		
		//그리기 
		function tool_pencil ()                                   
		{
		    var tool = this;
		    this.started = false;
		    // 마우스를 누르는 순간 그리기 작업을 시작 한다. 
		    this.mousedown = function (ev) 
		    {
		        context.beginPath();
		        context.moveTo(ev._x, ev._y);
		        tool.started = true;
		    };
		   // 마우스가 이동하는 동안 계속 호출하여 Canvas에 Line을 그려 나간다
		    this.mousemove = function (ev) 
		    {
		        if (tool.started) 
		        {
		            context.lineTo(ev._x, ev._y);
		            context.stroke();
		        }
		    };
		   // 마우스 떼면 그리기 작업을 중단한다
		    this.mouseup = function (ev) 
		    {
		      if (tool.started){
		            tool.mousemove(ev);
		            tool.started = false;
		      }
		    };
		}       
		
		// Canvas요소 내의 좌표를 결정 한다.
		function ev_canvas (ev) 
		{
			position = $(this).offset();
		    if (ev.pageX || ev.pageY == 0) 
		    { // Firefox 브라우저
		      ev._x = event.pageX - position.left
		      ev._y = event.pageY - position.top;
		    } 
		    // tool의 이벤트 핸들러를 호출한다.
		    var func = tool[ev.type];        
		    if (func) {
		        func(ev);
		    }
		}
		
</script>

				<!-- ********************** tabs 3***************************** -->
					<div id="tabs-3" class="tab3">
						<div class="xray_img">
							<canvas id="canvasbox" width="350px" height="400px">
							
							</canvas>
						</div>
						<p style="margin-left: 130px; margin-top: 30px;">
							<strong>검사 받은 자료 목록</strong>
						</p>
						<div class="img_list_content">
							<table class="img_list">
								
							</table>
						</div>
					</div>
					
					
					
					
					
					<!-- ***************************** tabs4!! ***************************** -->
					<div id="tabs-4">
						<div>
							<select id="ca_name" name="ca_name"	onchange="select(this.value);">
								<option class="selected_jindan" value="default" selected>
								-- 진단서 유형 --</option>
								<option value="CTF01">상해 진단서</option>
								<option value="CTF02">사망 진단서</option>
							</select>
						</div>

						<div class="sanghae" id="sanghae" style="display: none;">
							<h1>상 해 진 단 서</h1>
							<table class="jindan_sanghae">
								<tr>
									<th class="th_sanghae">진단서 등록번호</th>
									<td class="td_sanghae"><input type="text" class="jindanseo_jupsoo_id" name="jindanseo_jupsoo_id"  readonly></td>
								</tr>
								<tr>
									<th class="th_sanghae">환자 이름(대상자)</th>
									<td class="td_sanghae"><input type="text" class="name" name="name" readonly></td>
								</tr>
								<tr>
									<th class="th_sanghae">주민등록 번호</th>
									<td class="td_sanghae"><input type="text" class="jumin1" name="jumin1" readonly> - <input type="text" class="jumin2" name="jumin2" readonly> </td>
								</tr>
								<tr>
									<th class="th_sanghae">질 병 명</th>
									<td class="td_sanghae"><input type="text" placeholder="해당 환자의 병명 입력"></td>
								</tr>
								<tr>
									<th class="th_sanghae">상해(발병)일자</th>
									<td class="td_sanghae"><input type="text" class="injury_date" placeholder="일자 입력"></td>
								</tr>
								<tr>
									<th class="th_sanghae">의사 소견</th>
									<td class="td_sanghae"><textarea rows="6" cols="50"	placeholder="의사 소견 입력"></textarea></td>
								</tr>
								<tr>
									<th class="th_sanghae">진단서 발행일자</th>
									<td class="td_sanghae"><input type="text" name="jupsoo_date"  readonly class="jupsoo_date" placeholder="2014-08-11"></td>
								</tr>
								<tr>
									<th class="th_sanghae">담당 의사</th>
									<td class="td_sanghae"><input type="text" readonly value="${name2}"></td>
								</tr>
							</table>

						</div>
						<div class="sanghae" id="samang" style="display: none;">
							<h1>사 망 진 단 서</h1>
							<table class="jindan_sanghae">
								<tr>
									<th class="th_sanghae">진단서 등록번호</th>
									<td class="td_sanghae"><input type="text" class="jindanseo_jupsoo_id2" readonly name="jindanseo_jupsoo_id2" ></td>
								</tr>
								<tr>
									<th class="th_sanghae">환자 이름(대상자)</th>
									<td class="td_sanghae"><input type="text" class="name2" readonly name="name2"></td>
								</tr>
								<tr>
									<th class="th_sanghae">주민등록 번호</th>
									<td class="td_sanghae"><input type="text" class="jumin3" readonly name="jumin3"><input type="text" class="jumin4" readonly name="jumin4"></td>
								</tr>
								<tr>
									<th class="th_sanghae">사망 일자</th>
									<td class="td_sanghae"><input type="text" class="death_date" placeholder="사망일자 입력"></td>
								</tr>
								<tr> 
									<th class="th_sanghae">사망 장소</th>  
									<td class="td_sanghae"><input type="text" class="death_location" placeholder="사망 장소 입력"></td>
								</tr>
								<tr>
									<th class="th_sanghae">상해(발병)일자</th>
									<td class="td_sanghae"><input type="text" placeholder="상해일자 입력"></td>
								</tr>
								<tr>
									<th class="th_sanghae">의사 소견</th>
									<td class="td_sanghae"><textarea rows="6" cols="50"
											placeholder="의사 소견 입력"></textarea></td>
								</tr>
								<tr>
									<th class="th_sanghae">진단서 발행일자</th>
									<td class="td_sanghae"><input type="text" readonly name="jupsoo_date2" class="jupsoo_date2"
										placeholder="발행일자 입력"></td>
								</tr>
								<tr>
									<th class="th_sanghae">담당 의사</th>
									<td class="td_sanghae"><input type="text" readonly value="${name2}"></td>
								</tr>
							</table>
						</div>
						<div class="btn_complete">
							<button type="button">초기화</button>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<button type="button" class="jindan_btn">완 료</button>
						</div>
					</div>
				</div>
			</div>

			<!-- side -->
			<div class="waitinglist">
					<div id="ddd" style="display:none; background-color: aqua;">
							${list2.patient_id}${list2.jupsoo_time }${list2.name}
						</div>
					<div class="list">
						<div id="infoDiv">	
						</div>	
						<div id="Info" class="Info">
							<input type="hidden" name="cheobang_temp_id" class="cheobang_temp_id" >
						</div>
						<button type="button" class="button1" id="button1">진료</button>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<button type="button"class="delbutton">삭제</button>
						
						<div class="waitinglist_content">
							<table class="watinglist_table">
								<tr>
									<th>접수 번호</th>
									<th>환자명</th>
									<th>접수 시간</th>
									<th></th>
								</tr>
								<c:forEach items="${list}" var="list2">
									<tr class="selectname" >
										<td><input class="textval" id="jupsooID" name="jupsoo_id" type="text"
											value="${list2.jupsoo_id}" readonly>
											</td>
										<td><input class="textval" type="text" id="patientName"
											value="${list2.name }" readonly></td>
										<td><input class="textval" type="text" id="jupsooTime"
											value="${list2.jupsoo_time}" readonly> 
											<input id="infolist"type="hidden" value="${list2.patient_id} | ${list2.name} | ${list2.jupsoo_time}">
										</td>
										<td><input id="patientid" name="patientid" style="display: none;" type="text" value="${list2.patient_id}">
											<input type="hidden" name="content" class="content" value="${list2.content }">
											<input type="hidden" name="type" class="type" value="${list2.type }">
										</td>
									</tr>
								</c:forEach>
							</table>
						</div>
						
						<button  style="float: left; width: 70px; height: 30px; "    type="button" class="cheobangBtn">처　방</button>
							<div class="is_jindanseo_div" style="display: none;">
							    <button style='float: left; margin-left: 40px; margin-top:10px; width: 70px; height: 30px;'   type='button' class='JindanseoBtn'>진단서</button> 
							</div>
					</div>
				<div class="search_body" id="search_body" style="display: block;">				
					<div class="search_content" id="seosik_div" style="display: none;">					
						<div class="search">			
							<input type="text" id="inputtag" placeholder="서식지 검색">
							<button type="button" class="button1" id="seosik_searchbtn">검색</button>			
						</div>
						<table class="ptr">
										
						</table>
					</div>			
					<div class="search_content" id="disease_div" style="display: none;">
						<div class="search">
							<input type="text" id="inputtag2" placeholder="상병 검색">
							<button type="button" class="button1" id="diseasesearchbtn">검색</button>
						</div>
						<table class="ptr">
						</table>
					</div>
				</div>
				<div class="search_content" id="medicine_div" style="display: none;">
					<div class="search">
						<input type="text" id="inputtag3" placeholder="약 검색">
						<button type="button" class="button1" id="medi_search">검색</button>
					</div>
					<table class="ptr">
					</table>				
				</div>
			</div>
		</div>
	</div> --%>